import React from "react";
import ReactDOM from 'react-dom';
import App from './App';
import {HashRouter as Router, Route, Switch, Redirect} from "react-router-dom";
import { Provider } from 'react-redux'; //用来共享数据
import {mainRouter} from "./router";
//store
import store from './store';

ReactDOM.render(
    <Provider store={store}>
    <Router>
        <Switch>
            <Route path="/admin" render={(routerProps)=>{
                //此处需要权限验证才能进行访问
                // console.log(routerProps);
                return <App {...routerProps}/>
            }}/>
            {
                mainRouter.map(route => {
                    return (<Route key={route.pathname} path={route.pathname} component={route.component}></Route>)
                })
            }
            {/* 访问/页面， 进入admin页面*/}
            <Redirect to="/admin" from="/" exact/>
            {/*访问其他不存在页面，跳转404*/}
            <Redirect to="/404"/>
        </Switch>
    </Router>
    </Provider>
    ,document.getElementById("root"));